/* GSTemporaryProductDao.java
 *
 * Project/Product: GWBS2009
 *
 * Modify Information:
 * =============================================================================
 *   Author	Date       Description
 *   ----------	---------- ---------------------------------------------------
 *   wzh	2009-12-18	First release
 *
 * Licensed Materials - Property of APEP
 * =============================================================================
 *    (C) COPYRIGHT Shanghai Auto Mart E-Procurement Co., Ltd. 2007 - 2009
 *    All Rights Reserved.
 *
 *    This software is the confidential and proprietary information of
 *    Shanghai Auto Mart E-Procurement Co., Ltd. ("Confidential Information").
 *    You shall not disclose such Confidential Information and shall use it only
 *    in accordance with the terms of the license agreement you entered into 
 *    with Shanghai Auto Mart E-Procurement Co., Ltd.
 *
 * Noties:
 * =============================================================================
 * 
 */

package com.hitrust.gs.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.hitrust.gs.bean.GSManufactureBean;
import com.hitrust.gs.bean.GSTemporaryProductBean;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.db.GSBaseDAO;
import com.hitrust.gs.util.exception.GSException;

import framework.core.DBConnection;
import framework.core.DBPreparedStatement;

public class GSTemporaryProductDao extends GSBaseDAO {
	
	public void saveByCon(GSTemporaryProductBean svo,DBConnection con) throws GSException {
        String sql = "insert into t_product_temporary values((select sys_guid() from dual),?,?,?,?,?,?,?,?,?,?,'0')";
        DBPreparedStatement pt = null;
        try {
            pt = con.prepareStatement(sql);
            pt.setString(1, svo.getConcentricity_code());
            pt.setString(2, svo.getTemporary_concentricity_code());
            pt.setString(3, svo.getWarehouse_code());
            pt.setString(4, svo.getWarehouse_name());
            pt.setString(5, svo.getCreate_user_id());
            pt.setString(6, svo.getCreate_user());
            pt.setString(7, svo.getCreate_time());
            pt.setString(8, svo.getLast_update_user_id());
            pt.setString(9, svo.getLast_update_user());
            pt.setString(10, svo.getLast_update_time());
            pt.executeUpdate();
        } catch (SQLException e) {
        	try {
				con.rollback();
			} catch (Exception e1) {
				GSLogWriter.error(e.getMessage(),e);
			}
            GSLogWriter.error(e.getMessage(),e);
            throw new GSException("保存替换临时产品表信息错误");
        } catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
 
                if (pt != null) {
                	try {
						pt.close();
					} catch (Exception e) {
						GSLogWriter.error(e.getMessage(),e);
					}
                }
           
        }

    }
	
    public void save(GSTemporaryProductBean svo) throws GSException {
        String sql = "insert into t_product_temporary values((select sys_guid() from dual),?,?,?,?,?,?,?,?,?,?,'0')";
        Connection conn = this.getConnetion();
        PreparedStatement pt = null;
        try {
            conn.setAutoCommit(false);
            pt = conn.prepareStatement(sql);
            pt.setString(1, svo.getConcentricity_code());
            pt.setString(2, svo.getTemporary_concentricity_code());
            pt.setString(3, svo.getWarehouse_code());
            pt.setString(4, svo.getWarehouse_name());
            pt.setString(5, svo.getCreate_user_id());
            pt.setString(6, svo.getCreate_user());
            pt.setString(7, svo.getCreate_time());
            pt.setString(8, svo.getLast_update_user_id());
            pt.setString(9, svo.getLast_update_user());
            pt.setString(10, svo.getLast_update_time());
            pt.execute();
            conn.commit();
            pt.close();
            conn.close();
        } catch (SQLException e) {
            try {
                if (conn != null) {
                    conn.rollback();
                    if (pt != null) {
                        pt.close();
                    }
                    conn.close();
                }

            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            e.printStackTrace();
            GSLogWriter.error(e.getMessage());
            throw new GSException("保存替换临时产品表信息错误");
        } finally {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
    public boolean findByCode(GSManufactureBean svo) throws GSException {
        String sql = "select * from  t_product_temporary where temporary_concentricity_code=? ";
        Connection conn = this.getConnetion();
        PreparedStatement pt = null;
        boolean falg = false;
        ResultSet rs =null;
        try {
            pt = conn.prepareStatement(sql);
            pt.setString(1, svo.getGs_concentricity());
            rs = pt.executeQuery();
            while(rs.next()){
                falg =true;
            }
            rs.close();
            pt.close();
            conn.close();
            return falg;
        } catch (SQLException e) {
            try {
                if (conn != null) {
                    conn.rollback();
                    if (pt != null) {
                        pt.close();
                        if(rs!=null){
                            rs.close();
                        }
                    }
                    conn.close();
                }

            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            e.printStackTrace();
            GSLogWriter.error(e.getMessage());
            throw new GSException("保存替换临时产品表信息错误");
        } finally {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
      
    }
    
    public boolean findByConcentricityCode(GSManufactureBean svo) throws GSException {
        String sql = "select * from  t_product_temporary where concentricity_code=? ";
        Connection conn = this.getConnetion();
        PreparedStatement pt = null;
        boolean falg = false;
        ResultSet rs =null;
        try {
            pt = conn.prepareStatement(sql);
            pt.setString(1, svo.getGs_concentricity());
            rs = pt.executeQuery();
            while(rs.next()){
                falg =true;
            }
            rs.close();
            pt.close();
            conn.close();
            return falg;
        } catch (SQLException e) {
            try {
                if (conn != null) {
                    conn.rollback();
                    if (pt != null) {
                        pt.close();
                        if(rs!=null){
                            rs.close();
                        }
                    }
                    conn.close();
                }

            } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            e.printStackTrace();
            GSLogWriter.error(e.getMessage());
            throw new GSException("保存替换临时产品表信息错误");
        } finally {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
      
    }
}
